const { DataTypes } = require('sequelize');
const { sequelize } = require('../utils/database');

const CheckIn = sequelize.define('CheckIn', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  activity_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  check_in_time: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  location_verified: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  latitude: {
    type: DataTypes.DECIMAL(10, 8),
    allowNull: true
  },
  longitude: {
    type: DataTypes.DECIMAL(11, 8),
    allowNull: true
  },
  badge_claimed: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  verification_code: {
    type: DataTypes.STRING(10),
    allowNull: true
  }
}, {
  tableName: 'check_ins',
  indexes: [
    {
      fields: ['user_id', 'activity_id'],
      unique: true
    },
    {
      fields: ['activity_id']
    },
    {
      fields: ['check_in_time']
    }
  ]
});

module.exports = CheckIn; 